using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class ResultOutputtingScript : MonoBehaviour
{
    public DiceSettings Settings;

    private StreamWriter outputStream;
    private void Awake()
    {
        if(string.IsNullOrWhiteSpace(Settings.OutputFile))
            return;
        var path = Path.GetFullPath(Settings.OutputFile, Application.streamingAssetsPath);
        outputStream = new StreamWriter(path, true, System.Text.Encoding.UTF8) { AutoFlush = false };
        outputStream.WriteLine($"======{DateTime.Now:yyyy/MM/dd HH:mm:ss}============");
        outputStream.WriteLine("side,headOrTail,neither");
        outputStream.Flush();
    }

    public void Record(int side, int headOrTail, int neither)
    {
        outputStream?.WriteLine($"{side},{headOrTail},{neither}");
        outputStream.Flush();
    }

    private void OnDestroy()
    {
        outputStream?.Dispose();
    }
}
